<template>
	<el-form :model="formData" ref="formRef" :rules="formRules" label-width="8rem">
		<el-row type="flex" :gutter="10">
			<el-col :span="24">
				<el-form-item label="开始年龄段" prop="start_year">
					<el-input
					    v-model="formData.start_year"
					    clearable
					    placeholder="请输入开始年龄段"
					></el-input>
				</el-form-item>
				<el-form-item label="结束年龄段" prop="end_year">
					<el-input
					    v-model="formData.end_year"
					    clearable
					    placeholder="请输入结束年龄段"
					></el-input>
				</el-form-item>
				<el-form-item label="排序" prop="sort">
					<el-input v-model="formData.sort" clearable  type="number" placeholder="请输入说明"></el-input>
				</el-form-item>
			</el-col>
		</el-row>
		<el-row type="flex" justify="center">
			<el-button type="primary" icon="el-icon-check" @click="onConfirm">确认</el-button>
			<el-button type="default" icon="el-icon-close" @click="onCancel">取消</el-button>
		</el-row>
	</el-form>
</template>

<script>
	export default {
		name: "member-search",
		props: {
			formData: {
				type: Object,
				default: () => {}
			},
		},
		components: {
			"el-upload-image": () => import("@/components/el-upload-image.vue"),
		},
		data() {
			return {
				formRules: {
					start_year: [{
						required: true,
						message: '请输入',
						trigger: 'change'
					}],
					end_year: [{
						required: true,
						message: '请输入',
						trigger: 'change'
					}],
					sort: [{
						required: true,
						message: '请输入',
						trigger: 'change'
					}],
				}
			};
		},
		methods: {
			onConfirm() {
				this.$refs.formRef.validate((valid) => {
					if (valid) {
						// alert('submit!');
						console.log(this.formData)
						this.$emit("search", this.formData);
						this.$parent.$emit("update:visible", false);
						this.$refs.formRef.resetFields()
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			onCancel() {
				this.$parent.$emit("update:visible", false);
				this.$refs.formRef.resetFields();
			}
		}
	};
</script>
